﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AdministratorHelper
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Minimized;
            this.ShowInTaskbar = false;
        }

        private static SelectForm selectForm = new SelectForm();
        private void MainForm_Load(object sender, EventArgs e)
        {
            HotKeyHelper.RegisterHotKey(this.Handle, 1001, (uint)KeyModifiers.Control, Keys.PageUp);
            //MessageBox.Show(AdminProcHelper.IsInRole(WindowsIdentity.GetCurrent()).ToString());
            notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
            //this.ShowInTaskbar = false;
            notifyIcon1.Visible = true;
        }



        protected override void WndProc(ref Message m)
        {
            const int WM_HOTKEY = 0x0312;
            switch (m.Msg)
            {
                case WM_HOTKEY:
                    //MessageBox.Show("");
                    if (selectForm == null || selectForm.IsDisposed)
                    {
                        selectForm = new SelectForm();
                    }
                    selectForm.TopMost = true;
                    selectForm.Show();
                    break;
            }
            base.WndProc(ref m);
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBoxButtons mbtns = MessageBoxButtons.OKCancel;
            if (MessageBox.Show("确定要退出吗？", "退出", mbtns) == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            AdminForm adminForm = new AdminForm();
            adminForm.Show();
        }

    }
}
